package microarray;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class MicroArrayServlet extends HttpServlet {
	
	public static final String TOOL = "tool=fmarino";

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		String termOne = req.getParameter("termOne");
		String termTwo = req.getParameter("termTwo");
		String reldate = req.getParameter("reldate");
		String retmax = req.getParameter("retmax");
		String sortby = req.getParameter("sortby");
		String db = req.getParameter("db");
		
		HttpSession session = req.getSession();
		
			Query queryOne = new Query(termOne, reldate, retmax, sortby, db);
			Query queryTwo = new Query(termTwo, reldate, retmax, sortby, db);
			String job = req.getParameter("job");
			session.setAttribute("job", job);
			if (job.equals("display")){
				session.setAttribute("queryOne", termOne);
				session.setAttribute("idsOne", queryOne.getSearch().getIDs());
				session.setAttribute("summariesOne", queryOne.getSummary());
				
				session.setAttribute("queryTwo", termTwo);
				session.setAttribute("idsTwo", queryTwo.getSearch().getIDs());
				session.setAttribute("summariesTwo", queryTwo.getSummary());
			}
			else
			{
				DataCompare dc = new DataCompare(queryOne.getFetch(), queryTwo.getFetch());
				dc.compare();
			
				session.setAttribute("rdSize", dc.toString());
			}
			
		resp.sendRedirect(resp.encodeRedirectURL("/microarray.jsp"));
	}
	
}
